﻿Public Class basic

    Private Sub basic_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim xSoal() As String = Split(System.IO.File.ReadAllText("soallevel1.txt"), vbCrLf)
        Dim carray As Integer = UBound(xSoal)
        Dim xLabelSoal(carray) As String
        Dim xPilihan(carray) As String
        Dim xJawaban(carray) As Integer

        Dim jumlahSoalLvl1 As Integer = carray

        randomizeArray(xSoal)

        For i As Integer = 0 To jumlahSoalLvl1
            Dim xTemp() As String = Split(xSoal(i), ";")
            xLabelSoal(i) = xTemp(0)
            xJawaban(i) = xTemp(4)
            xPilihan(i) = xTemp(1) & ";" & xTemp(2) & ";" & xTemp(3)
        Next


        For i As Integer = 0 To jumlahSoalLvl1
            Dim panelSoal As New level1
            panelSoal.Left = 0
            panelSoal.Top = 0
            panelSoal.Pilihan = xPilihan(i)
            panelSoal.IndexSoal = i
            panelSoal.jumSoal = jumlahSoalLvl1
            panelSoal.Jawaban = xJawaban(i)
            panelSoal.Soal = xLabelSoal(i)
            panelSoal.refreshSoal()
            Me.Controls.Add(panelSoal)
        Next
    End Sub
    Sub randomizeArray(ByVal items() As String)
        Dim mIndex As Integer = items.Length - 1
        Dim rnd As New Random
        For i As Integer = 0 To mIndex
            Dim j As Integer = rnd.Next(i, mIndex + 1)
            Dim temp As String = items(i)
            items(i) = items(j)
            items(j) = temp
        Next
    End Sub
End Class